package com.soft.config;

import com.soft.interceptor.LoginHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Locale;

//扩展SpringMVC, 扩展看需要实现的方法
@Configuration
public class UserConfig implements WebMvcConfigurer {

    @Bean
    public ViewResolver myViewResolver(){
        return new MyViewResolver();
    }
//    @ConfigurationProperties(prefix = "spring.datasource")
//    @Bean
//    public DataSource druidDatasoource(){
//        return new DriverDataSource();
//    }
    //重修方法实现拦截器，视图解析器等
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController( "/gyx" ).setViewName( "test" );
        //主页面
//        registry.addViewController("/user/index").setViewName("/user/index");
//        registry.addViewController("").setViewName("/user/index");
//        registry.addViewController("/index").setViewName("user/index");
//        registry.addViewController("/index.html").setViewName("/user/index");
        //用户登录页面
//        registry.addViewController("/user/login?cartList=&totalMoney=0").setViewName("user/login");
        registry.addViewController("/register").setViewName("/user/register");
        registry.addViewController("/loginout").setViewName("/user/login");

        //简单商品页面
        registry.addViewController("/single-product-simple.html").setViewName("/user/single-product-simple");
//        registry.addViewController("/single-product.html").setViewName("/user/single-product");
        registry.addViewController("/single-product-affiliate.html").setViewName("/user/single-product-affiliate");

        //商品展示
        registry.addViewController("/shop.html").setViewName("/user/shop");
        registry.addViewController("/shop-3-grid.html").setViewName("/user/shop-3-grid");


//        registry.addViewController("/checkout").setViewName("/user/checkout");
//        registry.addViewController("/checkout.html").setViewName("/user/checkout");

        registry.addViewController("/about-us.html").setViewName("/user/about-us");
        registry.addViewController("/hebing").setViewName("/user/hebing");
//        registry.addViewController("search").setViewName("/user/page-search");

        //联系我们
//        registry.addViewController("/contact").setViewName("/user/contact");
        //博客
//        registry.addViewController("/blog").setViewName("/user/blog");
        //关于我们
//        registry.addViewController("/about-us").setViewName("/user/about-us");
    }
    public class MyViewResolver implements ViewResolver {
        @Override
        public View resolveViewName(String viewName, Locale locale) throws Exception {
            return null;
        }
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new LoginHandlerInterceptor()).
////                .addPathPatterns("/**").
//                excludePathPatterns("index2","index", "/user/login", "/js/**","/css/*",
//                                    "/img/**", "/fonts/**","/image/**","/picture/**",
//                                    "*.js", "/images/**","/lay/**", "/layui/**","/img/**");
    }
}
